package com.sunny.l28;

public class Solution {
    public int maxProfit(int[] prices) {
        int b1 = Integer.MIN_VALUE;
        int s1 = 0;
        int b2 = Integer.MIN_VALUE;
        int s2 = 0;
        for(int p: prices){
            if(b1 < -1*p){
                b1 = -1*p;
            }
            if(s1 < p + b1){
                s1 = p + b1;
            }
            if(b2 < -1*p + s1){
                b2 = -1*p + s1;
            }
            if(s2 < p + b2){
                s2 = p + b2;
            }
        }
        return s2;
    }
}
